package com.union.official;

import com.union.official.common.util.EnvProfileUtils;
import com.union.official.common.util.IPUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

/**
 * 优联官网系统启动类
 *
 * @author 杨 强
 * @package com.union.official
 * @createTime 2024-03-06 14:28
 */
@Slf4j
@MapperScan({"com.union.official.mapper"})
@SpringBootApplication
public class UnionOfficialApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(UnionOfficialApplication.class, args);
        Environment environment = context.getBean(Environment.class);
        // 服务启动端口号
        String appPort = environment.getProperty("server.port");
        // 服务启动实例名称
        String appName = environment.getProperty("spring.application.name");
        // 服务启动IP地址
        String appIp = StringUtils.isBlank(IPUtils.getIp()) ? "127.0.0.1" : IPUtils.getIp();
        // 服务启动配置环境
        String env = EnvProfileUtils.getValue(environment.getProperty("spring.profiles.active")).value;
        // 服务注册发现地址
        String serverAddr = environment.getProperty("spring.cloud.nacos.discovery.server-addr");
        log.info("-----------------------------------------------------------------------------------------------");
        log.info("-------------- " + appName + " Running Success --------------");
        log.info("-------------- Server  name：" + appName + " --------------");
        log.info("-------------- Server  Port：" + appPort + " --------------");
        log.info("-------------- Server    IP：" + appIp + " --------------");
        log.info("-------------- Server   Env：" + env + " --------------");
        log.info("-------------- Nacos Server：" + serverAddr + " --------------");
        log.info("-----------------------------------------------------------------------------------------------");
    }
}
